<% add_decidim_page_title(t("decidim.admin.titles.initiatives_types")) %>

<div class="card" id="initiative-types">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t "decidim.admin.titles.initiatives_types" %>
      <%= link_to t("actions.new_initiative_type", scope: "decidim.admin"),
                  [:new, :initiatives_type],
                  class: "button button__sm button__secondary" if allowed_to? :create, :initiative_type %>
    </h1>
  </div>
  <div class="table-stacked">
    <table class="table-list">
      <thead>
        <tr>
          <th><%= t("models.initiatives_types.fields.title", scope: "decidim.admin") %></th>
          <th><%= t("models.initiatives_types.fields.created_at", scope: "decidim.admin") %></th>
          <th><%= t("initiatives_type.actions.title", scope: "decidim.resources") %></th>
        </tr>
      </thead>
      <tbody>
        <% @initiatives_types.each do |initiative_type| %>
        <tr>
          <td data-label="<%= t("models.initiatives_types.fields.title", scope: "decidim.admin") %>">
            <% if allowed_to? :update, :initiative_type, initiative_type: initiative_type %>
              <%= link_to translated_attribute(initiative_type.title), edit_initiatives_type_path(initiative_type) %>
            <% else %>
              <%= translated_attribute initiative_type.title %></td>
            <% end %>
          <td data-label="<%= t("models.initiatives_types.fields.created_at", scope: "decidim.admin") %>"><%= l initiative_type.created_at, format: :short %></td>
          <td class="table-list__actions" data-label="<%= t("initiatives_type.actions.title", scope: "decidim.resources") %>">
            <button type="button" data-controller="dropdown" data-target="actions-initiative-type-<%= initiative_type.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: initiative_type.title) %>">
              <%= icon "more-fill", class: "text-secondary" %>
            </button>

            <div class="inline-block relative">
              <ul id="actions-initiative-type-<%= initiative_type.id %>" class="dropdown dropdown__action" aria-hidden="true">
                <% if allowed_to? :update, :initiative_type, initiative_type: initiative_type %>
                  <li class="dropdown__item">
                    <%= link_to edit_initiatives_type_path(initiative_type), class: "dropdown__button" do %>
                      <%= icon "pencil-line" %>
                      <%= t("actions.configure", scope: "decidim.admin") %>
                    <% end %>
                  </li>
                <% end %>

                <li class="dropdown__item">
                  <%= free_resource_permissions_link(initiative_type) %>
                </li>

                <% if allowed_to? :destroy, :initiative_type, initiative_type: initiative_type %>
                  <hr>

                  <li class="dropdown__item">
                    <%= link_to initiative_type, method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button" do %>
                      <%= icon "delete-bin-line" %>
                      <%= t("actions.destroy", scope: "decidim.admin") %>
                    <% end %>
                  </li>
                <% end %>
              </ul>
            </div>
          </td>
        </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>
